//package com.sxkiler.demo.sharding.configuration;
//
//@Configuration
//@ComponentScan({ "org.apache.shardingsphere.spring.boot.converter" })
//@EnableConfigurationProperties({ SpringBootShardingRuleConfigurationProperties.class, SpringBootMasterSlaveRuleConfigurationProperties.class, SpringBootEncryptRuleConfigurationProperties.class, SpringBootPropertiesConfigurationProperties.class, SpringBootShadowRuleConfigurationProperties.class })
//@ConditionalOnProperty(prefix = "spring.shardingsphere", name = { "enabled" }, havingValue = "true", matchIfMissing = true)
//@AutoConfigureBefore({ DataSourceAutoConfiguration.class })
//public class SpringBootConfiguration implements EnvironmentAware
//{
//    private final SpringBootShardingRuleConfigurationProperties shardingRule;
//    private final SpringBootMasterSlaveRuleConfigurationProperties masterSlaveRule;
//    private final SpringBootEncryptRuleConfigurationProperties encryptRule;
//    private final SpringBootShadowRuleConfigurationProperties shadowRule;
//    private final SpringBootPropertiesConfigurationProperties props;
//    private final Map<String, DataSource> dataSourceMap;
//    private final String jndiName = "jndi-name";
//
//    @Bean
//    @Conditional({ ShardingRuleCondition.class })
//    public DataSource shardingDataSource() throws SQLException {
//        return ShardingDataSourceFactory.createDataSource((Map)this.dataSourceMap, new ShardingRuleConfigurationYamlSwapper().swap((YamlShardingRuleConfiguration)this.shardingRule), this.props.getProps());
//    }
//
//    @Bean
//    @Conditional({ MasterSlaveRuleCondition.class })
//    public DataSource masterSlaveDataSource() throws SQLException {
//        return MasterSlaveDataSourceFactory.createDataSource((Map)this.dataSourceMap, new MasterSlaveRuleConfigurationYamlSwapper().swap((YamlMasterSlaveRuleConfiguration)this.masterSlaveRule), this.props.getProps());
//    }
//
//    @Bean
//    @Conditional({ EncryptRuleCondition.class })
//    public DataSource encryptDataSource() throws SQLException {
//        return EncryptDataSourceFactory.createDataSource((DataSource)this.dataSourceMap.values().iterator().next(), new EncryptRuleConfigurationYamlSwapper().swap((YamlEncryptRuleConfiguration)this.encryptRule), this.props.getProps());
//    }
//
//    @Bean
//    @Conditional({ ShadowRuleCondition.class })
//    public DataSource shadowDataSource() throws SQLException {
//        return ShadowDataSourceFactory.createDataSource((Map)this.dataSourceMap, new ShadowRuleConfigurationYamlSwapper().swap((YamlShadowRuleConfiguration)this.shadowRule), this.props.getProps());
//    }
//
//    @Bean
//    public ShardingTransactionTypeScanner shardingTransactionTypeScanner() {
//        return new ShardingTransactionTypeScanner();
//    }
//
//    public final void setEnvironment(final Environment environment) {
//        final String prefix = "spring.shardingsphere.datasource.";
//        for (final String each : this.getDataSourceNames(environment, prefix)) {
//            try {
//                this.dataSourceMap.put(each, this.getDataSource(environment, prefix, each));
//            }
//            catch (ReflectiveOperationException ex) {
//                throw new ShardingSphereException("Can't find datasource type!", (Exception)ex);
//            }
//            catch (NamingException namingEx) {
//                throw new ShardingSphereException("Can't find JNDI datasource!", (Exception)namingEx);
//            }
//        }
//    }
//
//    private List<String> getDataSourceNames(final Environment environment, final String prefix) {
//        final StandardEnvironment standardEnv = (StandardEnvironment)environment;
//        standardEnv.setIgnoreUnresolvableNestedPlaceholders(true);
//        return (null == standardEnv.getProperty(prefix + "name")) ? new InlineExpressionParser(standardEnv.getProperty(prefix + "names")).splitAndEvaluate() : Collections.singletonList(standardEnv.getProperty(prefix + "name"));
//    }
//
//    private DataSource getDataSource(final Environment environment, final String prefix, final String dataSourceName) throws ReflectiveOperationException, NamingException {
//        final Map<String, Object> dataSourceProps = (Map<String, Object>)PropertyUtil.handle(environment, prefix + dataSourceName.trim(), (Class)Map.class);
//        Preconditions.checkState(!dataSourceProps.isEmpty(), (Object)"Wrong datasource properties!");
//        if (dataSourceProps.containsKey("jndi-name")) {
//            return this.getJndiDataSource(dataSourceProps.get("jndi-name").toString());
//        }
//        final DataSource result = DataSourceUtil.getDataSource(dataSourceProps.get("type").toString(), (Map)dataSourceProps);
//        DataSourcePropertiesSetterHolder.getDataSourcePropertiesSetterByType(dataSourceProps.get("type").toString()).ifPresent(dataSourcePropertiesSetter -> dataSourcePropertiesSetter.propertiesSet(environment, prefix, dataSourceName, result));
//        return result;
//    }
//
//    private DataSource getJndiDataSource(final String jndiName) throws NamingException {
//        final JndiObjectFactoryBean bean = new JndiObjectFactoryBean();
//        bean.setResourceRef(true);
//        bean.setJndiName(jndiName);
//        bean.setProxyInterface((Class)DataSource.class);
//        bean.afterPropertiesSet();
//        return (DataSource)bean.getObject();
//    }
//
//    public SpringBootConfiguration(final SpringBootShardingRuleConfigurationProperties shardingRule, final SpringBootMasterSlaveRuleConfigurationProperties masterSlaveRule, final SpringBootEncryptRuleConfigurationProperties encryptRule, final SpringBootShadowRuleConfigurationProperties shadowRule, final SpringBootPropertiesConfigurationProperties props) {
//        this.dataSourceMap = new LinkedHashMap<String, DataSource>();
//        this.shardingRule = shardingRule;
//        this.masterSlaveRule = masterSlaveRule;
//        this.encryptRule = encryptRule;
//        this.shadowRule = shadowRule;
//        this.props = props;
//    }
//}
//
